{% extends "base.html" %}
{% load navigation_tags %}
{% load authorization_tags %}
{% block content %}
    {{ block.super }}
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-heading tight">
                    <h3 class="has-filters">
                        Note Type List
                        <div class="dropdown pull-right">
                            <button id="show-filters" aria-label="Filters" data-toggle="collapse" data-target="#the-filters" class="btn btn-primary toggle-filters"> <i class="fa-solid fa-filter"></i> <i class="caret"></i> </button>
                            {% if "dojo.add_note_type"|has_configuration_permission:request %}
                            <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1"
                                  data-toggle="dropdown" aria-expanded="true" aria-label="Note type options">
                              <span class="fa-solid fa-screwdriver-wrench"></span>
                              <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-right" role="menu"
                                aria-labelledby="dropdownMenu1">
                                    <li role="presentation">
                                        <a href="{% url 'add_note_type' %}">
                                            <i class="fa-solid fa-plus"></i> Add Note Type
                                        </a>
                                    </li>
                            </ul>
                            {% endif %}
                        </div>
                    </h3>
                </div>
                <div id="the-filters" class="is-filters panel-body collapse {% if ntl.form.has_changed %}in{% endif %}">
                    {% include "dojo/filter_snippet.html" with form=ntl.form %}
                </div>
            </div>
            {% if nts %}

                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=nts page_size=True %}
                </div>

                <div class="panel panel-default table-responsive">
                    <table id="note_types"
                           class="tablesorter-bootstrap table table-condensed table-striped">
                        <thead>
                        <tr>
                            {% comment %} The display field is translated in the function. No need to translate here as well{% endcomment %}
                            <th>{% dojo_sort request 'Note Type' 'name' 'asc' %}</th>
                            <th> Description</th>
                            <th> Single/Multiple</th>
                            <th> Mandatory/Optional</th>
                            <th> Active/Disabled</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for nt in nts %}
                            <tr>
                              <td><a> {{ nt.name }} </a></td>
                              <td><a>{{ nt.description }}</a></td>
                              <td>
                                {% if nt.is_single %}
                                  <a>Single</a>
                                {% else %}
                                  <a>Multiple</a>
                                {% endif %}
                              </td>
                              <td>
                                {% if nt.is_mandatory %}
                                  <a>Mandatory</a>
                                {% else %}
                                <a>Optional</a>
                                {% endif %}
                              </td>
                              <td>
                                {% if nt.is_active %}
                                  <a>Active</a>
                                {% else %}
                                <a>Disabled</a>
                                {% endif %}
                              </td>
                              {% if "dojo.change_note_type"|has_configuration_permission:request %}
                                    <td>
                                        <div class="centered">
                                            <div class="btn-group" role="group">
                                                <a class="btn btn-sm btn-warning"
                                                   href="{% url 'edit_note_type' nt.id %}">
                                                    <i class="fa-solid fa-file"></i> Edit Note Type
                                                </a>
                                                {% if nt.is_active %}
                                                <a class="btn btn-sm btn-danger"
                                                   href="{% url 'disable_note_type' nt.id %}">
                                                    <i class="fa-solid fa-xmark"></i> Disable Note Type
                                                </a>
                                                {% else %}
                                                <a class="btn btn-sm btn-success"
                                                   href="{% url 'enable_note_type' nt.id %}">
                                                    <i class="fa-solid fa-check"></i> Enable Note Type
                                                </a>
                                                {% endif %}
                                            </div>
                                        </div>
                                    </td>
                                {% endif %}

                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
                <div class="clearfix">
                    {% include "dojo/paging_snippet.html" with page=nts page_size=True %}
                </div>
            {% else %}
                <p class="text-center">No Note types found.</p>
            {% endif %}
        </div>
    </div>
{% endblock %}
{% block postscript %}
    {{ block.super }}
    <script>
        $(function () {
            var availableTags = [
                {% for word in name_words %}
                    "{{word}}",
                {% endfor %}
            ];
            $("#id_name").autocomplete({
                source: availableTags
            });
        });
    </script>
    {% include "dojo/filter_js_snippet.html" %}
{% endblock %}
